package com.guojian.jdbc.sql;

import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.util.JdbcUtils;
import com.github.pagehelper.parser.CountSqlParser;
import com.guojian.jdbc.DBType;

//@Component
//@ConditionalOnProperty(value = "pagehelper.helperDialect", havingValue = "mysql")
public class MysqlParser implements SqlParser {

	private final CountSqlParser countParser = new CountSqlParser();

	@Override
	public String getCountSql(String sql) {
		return countParser.getSmartCountSql(sql);
	}

	@Override
	public String getPageSql(String sql, Integer offset, Integer limit) {
		StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(sql);
		sqlBuilder.append(" LIMIT  " + offset + "," + limit);
		return sqlBuilder.toString();
	}

	@Override
	public DBType getDBType() {
		return DBType.mysql;
	}

	public static void main(String[] args) {
		String sql = " select * from user where name='guojian' ";
		String pageSql = new SqlServerParser().convertToPageSql(sql, 10, 10);
		String formatPageSql = SQLUtils.format(pageSql, JdbcUtils.SQL_SERVER);
		System.out.println(formatPageSql);

	}

}
